import { ListPage } from './..//pages/list/list';
import { HelloIonicPage } from './../pages/hello-ionic/hello-ionic';
import { Component, ViewChild } from '@angular/core';
import { Platform, MenuController, Nav } from 'ionic-angular';
import { StatusBar, Splashscreen } from 'ionic-native';
import { SexyService } from "./app.service";

@Component({
  templateUrl: 'app.html'
})
export class MyApp {

  @ViewChild(Nav) nav: Nav;
  rootPage: any = HelloIonicPage;
  pages: Array<{ item: any, component: any }> = [];

  constructor(public platform: Platform,
    public menu: MenuController,
    public sexyService: SexyService
  ) {
    platform.ready().then(() => {
      StatusBar.styleDefault();
      Splashscreen.hide();
    });
  }

  ngOnInit() {
    // 动态获取抽屉菜单
    this.sexyService.getMenuItems().subscribe(rs => {
      var data = rs.tngou;
      for (var i = 0; i < data.length; i++) {
        var c = data[i];
        // 组织新的数据
        this.pages.push({
          item: { id: c.id, title: c.title },
          component: ListPage
        })
      }
    })
  }

  openPage(page) {
    this.menu.close();
    this.nav.push(page.component, {
      item: page.item
    });
  }

}
